﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace Landscape.Elements
{
    internal class Widget
    {
        public string Name;
        public string Content;
        public Dictionary<string, object> Params = new Dictionary<string, object>();

        public Widget() { 
        
        }

        public Widget(XmlReader source) {
            if (source.HasAttributes) {
                while (source.MoveToNextAttribute()) {
                    if (source.Name == "name") {
                        Name = source.Value;
                    } else {
                        if (string.IsNullOrEmpty(source.NamespaceURI)) {
                            Params.Add(source.Name, source.Value);                        
                        }
                    }
                }
                source.MoveToContent();
                Content = source.ReadInnerXml();
            }

            if (string.IsNullOrEmpty(Name)) {
                throw new Exception("Attribute 'name' is missing or empty.");
            }
        }
    }
}
